package com.xxx.test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.xxx.DAO.booksDao;
import com.xxx.entity.Book;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


@WebServlet("/huixian_text")
public class huixian_text extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String inputValue = request.getParameter("inputValue");
        String json="{\"firstName\":\""+inputValue+"\",\"lastName\":\"xuJia\"}";
        System.out.println(json);

        //需要使用jackson包把Book对象转换为json
//        ObjectMapper om=new ObjectMapper();
//        json=om.writeValueAsString(book);
        //把获取的数据，通过网络传给ajax中的异步对象，响应结果数据
        //指定服务器端（servlet）返回给浏览器的是json格式的数据
        response.setContentType("application/json;charset=utf-8");
        PrintWriter pw=response.getWriter();
        pw.println(json);//输出数据，会赋值给Ajax中responseText属性
        pw.flush();
        pw.close();
    }
}
